package com.zhdl.modules.process.task;

import com.project.command.faq.state.LinkStateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 公共的定时任务
 */
@Slf4j
@Component
public class CommonScheduledTask {

    @Resource
    private LinkStateService linkStateService;

    /**
     * 所有端口状态Map
     */
    public static Map<String,Boolean> allPortStates;

    /**
     * 检查 串口/网口 的链接状态
     * 读取时间与重连时间保持一致 2s
     */
    @Scheduled(fixedRate = 2000, initialDelay = 1000)
    public void myTask() {
        //获取
        allPortStates = linkStateService.getAllPortStates();
        if (allPortStates != null) {
            for (String key : allPortStates.keySet()) {
                if (!allPortStates.get(key)) {
                    log.info("allPortStates==key={},value={}", key,allPortStates.get(key));
                }
            }
        } else {
            log.info("allPortStates=null");
        }
    }
}
